package ModelLayer;

import java.util.ArrayList;

public class Adressebog
{
    private ArrayList<Person> personList;
    

    
    public Adressebog()
    {
        personList = new ArrayList<Person>();
    }
    
    /**
     * Adds a person to the adressebog
     */
    public void addPerson(Person person)
    {
    int index = 0;
    boolean found = personList.contains(person);
    if(index < personList.size() && found)
    {
        index++;
        found = false;
        System.out.println("Personen er allerede regisreret.");
    }
    else
    {
        personList.add(person);
    }
}
    
    
    public void removeFile(String id)
    {
    int index = 0;
    boolean found = false;
    while(index < personList.size() && !found)
    {
    if(personList.get(index).getId().contains(id))
    {
        personList.remove(index);
        found = true;
    }
    else
    {
        index++;
    }
    }
}  
    public Person getPersons(String id)
    {
        int i = 0;
        boolean found = false;
        while ( !found && i<personList.size()) 
        {
        if ( id.equals (personList.get(i).getId())){
            found = true;
        }
            else 
            {
                i++;
            }
        }
            if(found)
            {
                return personList.get(i);
            }
            else {
                return null;
            }
    
    // return personList.get(i);
    
    }
    public void listAllPersons()
    {
        int index = 0;
        while(index < personList.size())
        {
            Person p = personList.get(index);
            p.listAllPerson();
            index++;
        }
    }
     public void setPerson(String id, String navn, String adresse, String postNr, String by, String tlf)
    {
        Person p = getPersons(id);
        p.setAllInformation(id, navn, adresse, postNr, by, tlf);
        System.out.println(" ");
    }

}











